package logic

import (
	"context"
	"go_zero_list/mode"

	"go_zero_list/doctor_rpc/doctor_rpc"
	"go_zero_list/doctor_rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddLogic) Add(in *doctor_rpc.AddRequest) (*doctor_rpc.AddResponse, error) {
	// todo: add your logic here and delete this line
	var doctor mode.Doctor
	doctor.Name = in.Doctor.Name
	doctor.Image = in.Doctor.Image
	doctor.FormHos = in.Doctor.FormHos
	doctor.Title = in.Doctor.Title
	doctor.FormDep = in.Doctor.FormDep
	doctor.Des = in.Doctor.Des
	if doctor.CreateDoctor() != nil {
		return &doctor_rpc.AddResponse{Id: 0}, nil
	}
	if doctor.GetDoctorByName() != nil {
		return &doctor_rpc.AddResponse{Id: 0}, nil
	}
	return &doctor_rpc.AddResponse{Id: int64(doctor.ID)}, nil
}
